home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-30 | 9.3 KB | 72 lines | [TEXT/R*ch] |
-
- (***********************************************************************
- | Structure Charpics containing ABSTRACT TYPE PICTURE |
- | |
- | (Uses Chrisprelude) |
- | |
- | C.M.P.Reade Oct 1987 |
- | |
- | (Comments at End) |
- ***********************************************************************)
-
- structure Charpics = struct
-
-
- local open Chrisprelude; infix upto in
-
- abstype picture = Pic of int * int * string list
- with
- fun mkpic linelist
- = let val d = length linelist;
- val shape = map size linelist;
- val w = maxposlist shape;
- fun addspaces line = let val a = size line in
- if a<w then line^spaces(w-a)
- else line
- end;
- val checkedlines = map addspaces linelist
- in Pic(d,w,checkedlines) end;
-
- fun depth (Pic(d,_,_)) = d;
- fun width (Pic(_,w,_)) = w;
- fun linesof (Pic(_,_,sl)) = sl;
- val nullpic = Pic(0,0,[]);
- fun padside n (pic as Pic(d,w,sl))
- = if n <= w then pic
- else Pic(d,n,map (fn s=>s^spaces(n-w)) sl);
- fun padbottom n (pic as Pic(d,w,sl))
- = if n <= d then pic
- else Pic(n,w,sl @ copy (n-d) (spaces w));
- fun rowwith fsb piclist
- = let val d' = maxposlist(map depth piclist);
- val blocks = map (linesof o padbottom d') piclist;
- fun mkline n = stringwith fsb (map (select n) blocks);
- val sl' = map mkline (1 upto d');
- val w' = if null sl' then 0 else size(hd sl')
- in Pic(d',w',sl') end;
-
- val row = rowwith ("","","");
-
- fun colwith (f,s,b) piclist
- = let val w' = maxposlist(map width piclist);
- val flines = map (implode o (copy w')) (explode f);
- val slines = map (implode o (copy w')) (explode s);
- val blines = map (implode o (copy w')) (explode b);
- val sl' = linkwith(flines,slines,blines)
- (map (linesof o padside w') piclist);
- val d' = length sl'
- in Pic(d',w',sl') end;
-
- val column = colwith ("","","");
-
- fun indent n (pic as Pic(d,w,sl))
- = if n<1 then pic
- else Pic(d,w+n,map (concat(spaces n)) sl);
-
- fun lower n (pic as Pic(d,w,sl))
- = if n<1 then pic
- else Pic(d+n,w,copy n (spaces w) @ sl);
-
- fun table [] = nullpic |
- table piclistlist
- = let fun mkrect piclistlist (* makes sure each list has same length